package de.clapp.client.order;

import java.util.ArrayList;

public class OrderModel
{
    private static OrderModel instance = new OrderModel();
    
    public static OrderModel getInstance() { return instance; }
    
    
    private ArrayList<IOrderPanel> observerlist;
    private OrderListModel listModel;
    
    
    private OrderModel()
    {
        this.observerlist = new ArrayList<IOrderPanel>();
    }
    
    public OrderListModel getListModel()
    {
        return listModel;
    }

    public void setListModel(OrderListModel listModel)
    {
        this.listModel = listModel;
    }

    public void addObserver(IOrderPanel view)
    {
        this.observerlist.add(view);
    }
    
    public void fillList()
    {
        for (IOrderPanel o : observerlist)
        {
            o.setOrderData();
        }
    }
    
    public void fillOrders()
    {
        listModel.fillList();
        fillList();
    }


    public void refreshData()
    {
        this.listModel.refreshData();
        for(IOrderPanel o : observerlist)
        {
            o.resetSelectedIndex();
            o.setOrderData();
        }
    }

    
    public void changeOrderStatus()
    {
        for (IOrderPanel o : observerlist)
        {
            int i = o.getSelectedOrder();
            listModel.getElementAt(i).setAbgeschlossen(true);
            o.setOrderData();
        }
    }
    
    
}
